'use strict';

define(['angular', 'angular-ui-router', '../../common/utils/service', '../../mstore/member/center/center', '../../mstore/login/login'], function (angular) {
	var module = angular.module('mstoreHome', ['ui.router', 'dataService', 'memberCenter', 'login']);
	module.config(['$stateProvider', function ($stateProvider) {
		$stateProvider
			.state("home", {
				url: '/home',
				controller: 'HomeCtrl',
				templateUrl: '/mstore/home/home.html'

			})
	}]);

	module.controller('HomeCtrl', ['$rootScope', '$state', '$scope', 'dataService', 'appService', 'growl', function ($rootScope, $state, $scope, dataService, appService, growl) {
		$scope.dataObj = sessionStorage.storeInfo && JSON.parse(sessionStorage.storeInfo);
		if (!$scope.dataObj) {
			$rootScope.showMessage("店铺错误");
			return;
		}
		$rootScope.pageTitle = $scope.dataObj.merchant.storename;

		$scope.memberBound(function () {
			dataService.getMemberInfo(sessionStorage.memberId, function (err, dataObj) {
				if (err) return;
				$scope.member = dataObj.member;
			})
		})

		$scope.gotoMember = function (memberId) {
			if (!sessionStorage.storeInfo) {
				$rootScope.showMessage('该店铺不能绑定会员');
				return;
			}
// 			if (memberId) {
			$state.transitionTo("member");
// 			} else {
// 				$state.transitionTo("login");
// 			}
		}
		var _cursObj = document.getElementById('markPoint').childNodes;
		var cursLen = _cursObj.length;
		window.mySwipe = new Swipe(document.getElementById('slider'), {
			startSlide: 0,
			speed: 400,
			auto: 3000,
			continuous: true,
			disableScroll: false,
			stopPropagation: false,
			callback: function (index, elem) {
				for (var i = 0; i < cursLen; i++) {
					_cursObj[i].className = '';
				}
				_cursObj[index].className = 'current';
			},
			transitionEnd: function (index, elem) {
			}
		});

	}]);
});
